home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / IBPalettes / WW3DKit / WW3DShapeBrowser.m < prev    next >
Encoding:
Text File  |  1995-03-22  |  3.9 KB  |  156 lines

  1. // copyright 1993 Michael B. Johnson; some portions copyright 1994, MIT
  2. // see COPYRIGHT for reuse legalities
  3. //
  4.  
  5. #import "WW3DShapeBrowser.h"
  6. #import "WW3DShapeCell.h"
  7. #import "WW3DShapeMatrix.h"
  8. #import "WW3DShape.h"
  9. #import "WW3DCamera.h"
  10. #import "WW3DWell.h"
  11. #import "WW3DShader.h"
  12. #import "WW3DShapeControlPanel.h"
  13.  
  14. @implementation WW3DShapeBrowser
  15.  
  16. - initFrame:(const NXRect *)r 
  17. {
  18.    self = [super initFrame:r];
  19.    [self setCellClass:[WW3DShapeCell class]];
  20.    [self setMatrixClass:[WW3DShapeMatrix class]];
  21.    [self setDelegate:self];
  22.    [self setMultipleSelectionEnabled:NO];
  23.    [self setTarget:self];
  24.    [self setAction:@selector(singleClick:)];
  25.    [self setDoubleAction:@selector(doubleClick:)];
  26.    shapeControlPanel = [[WW3DShapeControlPanel alloc] init];
  27.    return self;
  28. }
  29.  
  30. - awake
  31. {
  32.    [super awake];
  33.  
  34.    [self setCellClass:[WW3DShapeCell class]];
  35.    [self setMatrixClass:[WW3DShapeMatrix class]];
  36.    [self setDelegate:self];
  37.    [self setMultipleSelectionEnabled:NO];
  38.    [self setTarget:self];
  39.    [self setAction:@selector(singleClick:)];
  40.    [self setDoubleAction:@selector(doubleClick:)];
  41.    shapeControlPanel = [[WW3DShapeControlPanel alloc] init];
  42.  
  43.    return self;
  44. }
  45.  
  46. - free
  47. {
  48.   if (shapeControlPanel)
  49.   {  [shapeControlPanel free];
  50.   }
  51.   return [super free];
  52. }
  53.  
  54. - (BOOL)acceptsFirstResponder { return YES; }
  55.  
  56. - selectRootShape
  57. {
  58.    [[self matrixInColumn:0] selectCellAt:0 :0];
  59.    [self singleClick:[self matrixInColumn:0]];
  60.    return self;
  61. }
  62.  
  63. - singleClick:sender
  64. {
  65.   [[ribWell camera] setCurrentShape:[[sender selectedCell] shape]];
  66.   [ribWell revertShapeInspectorFor:[[sender selectedCell] shape]];
  67.   return self; 
  68. }
  69.  
  70. - updateShapeCamera
  71. {
  72.   [[ribWell camera] display];
  73.   return self; 
  74. }
  75.  
  76. - doubleClick:sender
  77. {
  78.   [[sender selectedCell] setEditable:YES];
  79.   return self; 
  80. }
  81.  
  82. - (int)browser:sender fillMatrix:matrix inColumn:(int)column
  83. {
  84.   int    row, howMany;
  85.   id    shapeCell, child, sibling, currentShape;
  86.     
  87.  
  88.   // In order to fill in a given column, we need to know what the
  89.   // currently selected cell in the column before it is.
  90.   // once we know that, we can query it for it's immediate children.
  91.   [matrix setBrowser:self];
  92.   currentShape = [[self selectedCell] shape];
  93.   if (!currentShape)  // if there is no selection
  94.   {  currentShape = [[ribWell camera] worldShape]; 
  95.      [matrix addRow];
  96.      shapeCell = [matrix cellAt:0 :0];    
  97.      [shapeCell setStringValue:[currentShape shapeName]];
  98.      [shapeCell setShape:currentShape];
  99.      [shapeCell setLoaded:YES];
  100.      if ([[currentShape children] count])
  101.      {  [shapeCell setLeaf:NO];
  102.      }
  103.      else
  104.      {  [shapeCell setLeaf:YES];
  105.      }
  106.      howMany = [[currentShape siblings] count];
  107.      for (row = 0; row < howMany; row++)
  108.      {  [matrix addRow];
  109.         sibling = [[currentShape siblings] objectAt:row];
  110.         shapeCell = [matrix cellAt:(row+1) :0];    
  111.         [shapeCell setStringValue:[sibling shapeName]];
  112.         [shapeCell setShape:sibling];
  113.         [shapeCell setLoaded:YES];
  114.         if ([[sibling children] count])
  115.         {  [shapeCell setLeaf:NO];
  116.         }
  117.         else
  118.         {  [shapeCell setLeaf:YES];
  119.         }
  120.      }
  121.      howMany++;  // to account for the first one
  122.   } 
  123.   else
  124.   {  howMany = [[currentShape children] count];
  125.      for (row = 0; row < howMany; row++)
  126.      {  [matrix addRow];
  127.         child = [[currentShape children] objectAt:row];
  128.         shapeCell = [matrix cellAt:row :0];    
  129.         [shapeCell setStringValue:[child shapeName]];
  130.         [shapeCell setShape:child];
  131.         [shapeCell setLoaded:YES];
  132.         if ([[child children] count])
  133.         {  [shapeCell setLeaf:NO];
  134.         }
  135.         else
  136.         {  [shapeCell setLeaf:YES];
  137.         }
  138.      }
  139.   }
  140.   [[[ribWell camera] worldShape] setSelected:NO andDrawOrigin:NO];
  141.   [[[self selectedCell] shape] setSelected:YES andDrawOrigin:[[ribWell camera] drawOriginForSelectedShape]];
  142.   
  143.   // need a flag for this; for now, let's not redisplay 
  144.   //[ribWell display];
  145.  
  146.   return howMany;
  147. }
  148.  
  149. - wellWasUpdated:well
  150. {
  151.   [self loadColumnZero];
  152.   return self;
  153. }
  154.  
  155. @end
  156.